<?php
/*
	插件页面op增删查改
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if($_RQ['page_id']){
	$_SESSION['page_id']=intval($_RQ['page_id']);
}
if(!$_SESSION['page_id']){
	exi('请先选择页面！','error');
}
$params=array(
	'page_id'=>$_SESSION['page_id'],
	'plugin_id'=>$_SESSION['plugin_id']
);
if($_RQ['op']=='list'){
	$result=cloud_request('plugin.cpage_op.list',$params);
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回页面列表','action'=>'app_develop.plugin.cpage'),
			array('op'=>'add','title'=>'添加页面动作'),
		),
		'list'=>array('data'=>'list','edit'=>false,'list'=>array(
			array('name'=>'name','title'=>'动作标识','type'=>'string'),
			array('name'=>'title','title'=>'动作名称','type'=>'string'),
		),'action'=>array(
			array('type'=>'href','op'=>'design','title'=>'设计'),
		)),
		'search_one'=>array('name'=>'title','add_op'=>'add'),
	);
	$result['htmls']=$htmls;
	exi($result);
}
if($_RQ['op']=='add'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$params['postdata']=$post;
		$id=cloud_request('plugin.cpage_op.post',$params);
		exi('创建成功！','','//design/id='.$id);
	}
	$id=intval($_RQ['id']);
	if($id){
		$params['id']=$id;
	}
	$result=cloud_request('plugin.cpage_op.edit',$params);
	$htmls=array(
		'type'=>'edit',
		'desc'=>'设计页面动作',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回页面动作列表'),
			
		),
		'edit'=>array(
			array('type'=>'string','title'=>'动作标识','name'=>'name', 'help'=>'动作标识，支持字母、数字、大小写，必须以字母开头。且不能和已有功能标识重复' ),
			array('type'=>'radio','title'=>'动作类型','name'=>'type','options'=>'types' ),
			array('type'=>'select','title'=>'指定主数据表','name'=>'table_id','options'=>'tables'),
		)
	);
	$result['htmls']=$htmls;
	exi($result);
}

if($_RQ['op'] == 'del'){
	if($_RQ['id']){
		$params['id']=intval($_RQ['id']);
	}
	if($_RQ['del']){
		$params['del']=trim($_RQ['del']);
	}
	$result=cloud_request('plugin.cpage_op.del',$params);
	exi($result);
}
if($_RQ['op']=='design'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$params['id']=intval($post['id']);
		if($post['type']>4){
			unset($post['id'],$post['type']);
			$params['postdata']=$post;
		}else{
			$params['postdata']=$post['design'];
		}
		
		$res=cloud_request('plugin.cpage_op.design',$params);
		exi($res);
	}
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择op~','error');
	}
	$params['id']=$id;
	$return=cloud_request('plugin.cpage_op.design',$params);
	$defaults=cfc('made_page')->get_template_default_mobile();
	foreach($defaults as &$default){
		foreach($default as &$row){
			if($row=='bitian'){
				$row='';
			}
		}
	}
	$return['defaults']=$defaults;
	exi($return);
}
